package com.txunda.zhuohired.fgt.manage;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.flyco.tablayout.SlidingTabLayout;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
import com.txunda.zhuohired.R;
import com.txunda.zhuohired.aty.manage.home.ManageAllAty;
import com.txunda.zhuohired.aty.manage.home.PostJobAty;
import com.txunda.zhuohired.base.Base2Fgt;
import com.txunda.zhuohired.fgt.manage.home.ManageHomeListFgt;

import java.util.ArrayList;
import java.util.List;

/**
 * 创建人： Txd_Cjh
 * 创建时间： 2018/3/10 14:32
 * 功能描述：推荐(首页)
 * 联系方式：jiahuanchen@126.com
 */

public class ManageHomeFgt extends Base2Fgt {
    /**
     * 标题
     */
    @ViewInject(R.id.tv_layout_manage_home_center)
    private TextView tv_layout_manage_home_center;

    /**
     * 返回
     */
    @ViewInject(R.id.iv_layout_blue_back)
    private ImageView iv_layout_blue_back;
    /**
     * SlidingTabLayout
     */
    @ViewInject(R.id.st_manage_home)
    private SlidingTabLayout st_manage_home;
    /**
     * viewPager
     */
    @ViewInject(R.id.vp_manage_home)
    private ViewPager vp_manage_home;

    private ArrayList<Fragment> mFragments;
    private MyPagerAdapter myPagerAdapter;

    private List<String> tittleList;
    private String[] tittleStr = {"UI设计师", "Android开发工程师", "IOS开发工程师", "PHP工程师", "项目经理"};

    @Override
    protected void immersionInit() {
        showStatusBar(R.id.layout_manage_home_head);
        tv_layout_manage_home_center.setText("推荐");
        iv_layout_blue_back.setVisibility(View.GONE);
    }

    @Override
    @OnClick({R.id.tv_manage_home_send_job, R.id.tv_layout_manage_home_right})
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.tv_manage_home_send_job://发布职位
                startActivity(PostJobAty.class, null);
                break;
            case R.id.tv_layout_manage_home_right://全部职位
                startActivity(ManageAllAty.class, null);
                break;
        }
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.fgt_manage_home;
    }

    @Override
    protected void initialized() {
        tittleList = new ArrayList();
        mFragments = new ArrayList<>();
        myPagerAdapter = new MyPagerAdapter(getActivity().getSupportFragmentManager());
        for (int i = 0; i < tittleStr.length; i++) {
            tittleList.add(tittleStr[i]);
        }
        for (int y = 0; y < tittleList.size(); y++) {
            mFragments.add(ManageHomeListFgt.getFgt(tittleList, y));
        }

    }

    @Override
    protected void requestData() {
        vp_manage_home.setAdapter(myPagerAdapter);
        st_manage_home.setViewPager(vp_manage_home);
        st_manage_home.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                if (0 == position) {
                    //                    getActivity().finish();
                }
            }

            @Override
            public void onTabReselect(int position) {
            }
        });
    }

    private class MyPagerAdapter extends FragmentPagerAdapter {
        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }


        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return tittleList.get(position);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }
    }
}
